//Ajax Request functions
var ajaxGet = function(what, params, where, on){
	new Request.HTML({
		headers: {'If-Modified-Since': 'Thu, 1 Jan 1970 00:00:00 GMT','Content-type':'text/html; charset=utf-8'},
		url: what,
		onRequest:function(){$(document.body).setStyle('cursor','progress');},
		method: 'get',
		evalScripts: true,
		evalResponse: true,
		update: where,
		onComplete : function(){on},
		onSuccess:function(){$(document.body).setStyle('cursor','auto');}
	}).send(params);
}
/*var ajaxSuggest = function(what, params, where, on){
	new Request({		
		url: what,
		evalScripts: true,
		evalResponse: true,
		update: where,
	}).send(params);
}*/
var ajaxPost = function(form, what, where, on){
	new Request.HTML({		
		url: what,
		onRequest:function(){$(document.body).setStyle('cursor','progress');},
		evalScripts: true,
		evalResponse: true,
		update: where,
		onSuccess:function(){$(document.body).setStyle('cursor','auto');}
	}).post(form);
}

var cancelEnterKey = function(e){
    var eKey;
    if (window.event) { //ie
        eKey = e.keyCode;
    }else 
        if (e.which) { // the (good) others
            eKey = e.which;
        }
    if(eKey == 13) {
		return false;
	}
}
var req=new Request();
var xsearch = function(searchfor){
	if(searchfor.length>=2){
		req.cancel();
		req = new Request({
				method: 'get',
				onRequest:function(){$(document.body).setStyle('cursor','progress');},
				url: 'tools/search.php?search='+searchfor,
				evalScripts:true,
				onSuccess:function(responseText){
					$('workspace').innerHTML=responseText;
					$(document.body).setStyle('cursor','auto');
				}
			}).send();
		$('frm_search').set('action','index.php?cat=search.php&search='+searchfor);
	}
}
var isPDF = function(el){
	var file = el.value.toLowerCase();
	var dotpos = file.lastIndexOf('.');
	var ext = file.substr(dotpos);
	if(ext=='.pdf'){
		return true;
	} else {
		var param = "color=rgb(255,168,142)&txt=Wrong file type! PDF-files are the only files valid for uploading. (Was type '" + ext + "')";
		ajaxGet("info.php", param, $('info'));
		return false;
	}	
}
window.addEvent('load', function(){
	$('workspace').setStyle('min-height',(window.getScrollHeight()-170-85));
	$('tools').setStyle('min-height',(window.getScrollHeight()-170));	
});

window.onresize=function(){
	$('workspace').setStyle('min-height',(window.getScrollHeight()-170-85));
	$('tools').setStyle('min-height',(window.getScrollHeight()-170));
};
//extends mootools 
Element.implement({ 
	highlight: function(search, insensitive, klass){
		var regex = new RegExp('(<[^>]*>)|('+ search.escapeRegExp() +')', insensitive ? 'ig' : 'g');
		return this.set('html', this.get('html').replace(regex, function(a, b, c){
			return (a.charAt(0) == '<') ? a : '<b class="'+ klass +'">' + c + '</b>'; 
		}));
	} 
});